package annotation.reflect;

//测试Class类的创建方式
public class TestClass {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("这个人是"+person.name);

        //1.通过对象获取
        Class class1 = person.getClass();

        //2.通过forName获取
        Class class2 = Class.forName("annotation.reflect.Student");

        //3.通过类获取
        Class class3 = Student.class;

        System.out.println(class1.hashCode());
        System.out.println(class2.hashCode());
        System.out.println(class3.hashCode());

        //4.基本内置类型的包装类都有一个Type属性
        Class<Integer> class4 = Integer.TYPE;
        Class<Integer> class5 = Integer.class;
        System.out.println(class4.hashCode());
        System.out.println(class5.hashCode());

        //获得父类类型
        System.out.println(class1.getName());
        Class class6 = class1.getSuperclass();
        System.out.println(class6);
    }
}

class Person{
    public String name;

    public Person() {

    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person {
    public Student() {
        this.name = "学生";
    }
}

class Teacher extends Person {
    public Teacher() {
        this.name = "老师";
    }
}